package com.pfzy.lib.sdk.log;

import java.io.File;
import java.io.FileFilter;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;

/**
 * 默认文件筛选器
 */
public class UXLogDefaultFileFilter implements FileFilter {
    @Override
    public boolean accept(File file) {
        boolean isFile = file.isFile();
        boolean isXlog = file.getName().endsWith(".xlog");
        SimpleDateFormat yyyyMMddFormat = new SimpleDateFormat("yyyyMMdd");
        boolean isToday = file.getName().indexOf(yyyyMMddFormat.format(Calendar.getInstance(Locale.getDefault()).getTimeInMillis())) > 0;
        boolean isYesterday = false;
        if (Calendar.getInstance(Locale.getDefault()).get(11) < 6) {
            isYesterday = file.getName().indexOf(yyyyMMddFormat.format(Calendar.getInstance(Locale.getDefault()).getTimeInMillis() - 86400000)) > 0;
        }
        return isFile && isXlog && (isToday || isYesterday);
    }
}
